﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Stone
{
    public partial class FormMain : Form
    {
        private Color Color_Tools_Selected = Color.FromArgb(220, 96, 96);
        private Color Color_Tools_UnSelected = Color.FromArgb(237, 237, 237);
        private enum Tool { Arrow, Button, Label }
        private Tool CurrentTool_ = Tool.Arrow;
        private Rectangle CurrentRectangle = new Rectangle();
        private bool MouseDown = false;
        private Point MouseDownPosition = new Point();
        private Skin skin = new Skin();
        private Skin_Screen currentScreen = new Skin_Screen();
        private Skin_Button currentButton = new Skin_Button();

        private Tool CurrentTool
        {
            get
            {
                return CurrentTool_;
            }
            set
            {
                button_Tools_Arrow.BackColor = Color_Tools_UnSelected;
                button_Tool_Button.BackColor = Color_Tools_UnSelected;
                button_Tool_Label.BackColor = Color_Tools_UnSelected;

                switch (value)
                {
                    case Tool.Arrow:

                        button_Tools_Arrow.BackColor = Color_Tools_Selected;
                        this.Cursor = Cursors.Default;

                        break;

                    case Tool.Button:

                        button_Tool_Button.BackColor = Color_Tools_Selected;
                        this.Cursor = Cursors.Cross; ;

                        break;

                    case Tool.Label:

                        button_Tool_Label.BackColor = Color_Tools_Selected;
                        this.Cursor = Cursors.Cross;

                        break;
                }

                CurrentTool_ = value;
            }

        }

        public FormMain()
        {
            InitializeComponent();
            Skin_Screen newScreen_Radio = new Skin_Screen();
            newScreen_Radio.Name = "Radio";
            skin.Screen_Add(newScreen_Radio);
            currentScreen = newScreen_Radio;
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void closeToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }        

        private void comboBox_ScreenSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox_ScreenSize.SelectedIndex == 0)
                panelScreen.Height = 480;

            if (comboBox_ScreenSize.SelectedIndex == 1)
                panelScreen.Height = 600;
        }

        private void FormMain_Load(object sender, EventArgs e)
        {
            comboBox_ScreenSize.SelectedIndex = 0;
        }

        private void button_Tools_Arrow_Click(object sender, EventArgs e)
        {
            CurrentTool = Tool.Arrow;
        }

        private void button_Tool_Button_Click(object sender, EventArgs e)
        {
            CurrentTool = Tool.Button;
        }

        private void button_Tool_Label_Click(object sender, EventArgs e)
        {
            CurrentTool = Tool.Label;
        }
        
        private void panelScreen_MouseDown(object sender, MouseEventArgs e)
        {
            MouseDown = true;
            MouseDownPosition = e.Location;

            if (CurrentTool == Tool.Button)
            {
                CreateButton(e.Location);
            }
        }

        private void CreateButton(Point mousePosition)
        {
            Skin_Button newButton = new Skin_Button();
            newButton.rectangle = new Rectangle(mousePosition, new Size(10, 10));
            currentButton = newButton;
            currentScreen.Button_Add(newButton);
        }

        private void panelScreen_MouseMove(object sender, MouseEventArgs e)
        {
            if (MouseDown)
            {
                if (CurrentTool == Tool.Button)
                {
                    currentButton.rectangle = new Rectangle(currentButton.rectangle.Location.X, currentButton.rectangle.Location.Y, e.Location.X - MouseDownPosition.X, e.Location.Y - MouseDownPosition.Y);
                    panelScreen.Invalidate();
                }
            }
        }

        private void panelScreen_MouseUp(object sender, MouseEventArgs e)
        {
            MouseDown = false;
        }

        private void panelScreen_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = panelScreen.CreateGraphics();

            foreach (Skin_Button tmp in currentScreen.buttons)
            {
                g.DrawRectangle(Pens.Black, tmp.rectangle);
            }
        }
    }
}
